﻿using System;
using System.Collections.Generic;
using System.Data;
using BLL;
using Utils;

namespace UI.ModSalary
{
    public partial class DefTax : System.Web.UI.Page
    {
        TaxBiz taxBiz = new TaxBiz();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                txtBegin.Text = taxBiz.GetBegin();
                BondData();
            }

        }
        private void BondData()
        {
            DataTable dt = taxBiz.GetLists();
            gvList.DataSource = dt;
            gvList.DataBind();
        }
        protected void btnAdd_Click(object sender, EventArgs e)
        {
            string code = txtTaxCode.Text.Trim();
            string bMoney = txtBMoney.Text.Trim();
            string eMoney = txtEMoney.Text.Trim();
            string constMoney = txtConstMoney.Text.Trim();
            string tax = txtTax.Text.Trim();
            if (string.IsNullOrWhiteSpace(code))
            {
                JSUtility.Alert(this, "序号必须输入");
                return;
            }
            if (!RegexRule.IsNumeric(bMoney) || !RegexRule.IsNumeric(eMoney) || !RegexRule.IsNumeric(constMoney) || !RegexRule.IsNumeric(tax))
            {
                JSUtility.Alert(this, "请输入数字");
                return;
            }
            SortedDictionary<string, string> sdList = new SortedDictionary<string, string>();
            sdList.Add("TaxCode", code);
            sdList.Add("BMoney", bMoney);
            sdList.Add("EMoney", eMoney);
            sdList.Add("ConstMoney", constMoney);
            sdList.Add("Tax", tax);
            if (taxBiz.Insert(sdList))
            {
                BondData();
                JSUtility.Alert(this, "增加成功");
            }
            else
                JSUtility.Alert(this, "增加失败");
        }

        protected void btnUpdate_Click(object sender, EventArgs e)
        {
            string code = txtTaxCode.Text.Trim();
            string bMoney = txtBMoney.Text.Trim();
            string eMoney = txtEMoney.Text.Trim();
            string constMoney = txtConstMoney.Text.Trim();
            string tax = txtTax.Text.Trim();
            if (string.IsNullOrWhiteSpace(code))
            {
                JSUtility.Alert(this, "序号必须输入");
                return;
            }
            if (!RegexRule.IsNumeric(bMoney) || !RegexRule.IsNumeric(eMoney) || !RegexRule.IsNumeric(constMoney) || !RegexRule.IsNumeric(tax))
            {
                JSUtility.Alert(this, "请输入数字");
                return;
            }
            SortedDictionary<string, string> sdList = new SortedDictionary<string, string>();
            sdList.Add("TaxCode", code);
            sdList.Add("BMoney", bMoney);
            sdList.Add("EMoney", eMoney);
            sdList.Add("ConstMoney", constMoney);
            sdList.Add("Tax", tax);
            if (taxBiz.Update(sdList))
            {
                BondData();
                JSUtility.Alert(this, "修改成功");
            }
            else
                JSUtility.Alert(this, "修改失败");
        }

        protected void btnDelete_Click(object sender, EventArgs e)
        {
            string code = txtTaxCode.Text.Trim();
            if (string.IsNullOrWhiteSpace(code))
            {
                JSUtility.Alert(this, "序号不能为空");
                return;
            }
            if (taxBiz.DeleteOneInfo(code))
            {
                BondData();
                JSUtility.Alert(this, "删除成功");
            }
            else
                JSUtility.Alert(this, "删除失败");
        }

        protected void btnBegin_Click(object sender, EventArgs e)
        {
         string beginMoney=   txtBegin.Text.Trim();
         string decreaseNum = txtDecreaseNum.Text.Trim();
         if (!RegexRule.IsNumeric(beginMoney) || !RegexRule.IsNumeric(decreaseNum))
         {
             JSUtility.Alert(this, "请输入数字");
             return;
         }

         if (taxBiz.UpdateBegin(beginMoney, decreaseNum))
            {
                JSUtility.Alert(this, "设置成功");
            }
            else
                JSUtility.Alert(this, "设置失败");

        }


    }
}